// 二进制操作

package kit

import (
	"bytes"
	"encoding/binary"
	"encoding/gob"
	"io/ioutil"
	"os"
)

// StoreBinary 存储成二进制文件
func StoreBinary(data interface{}, filename string) {
	buffer := new(bytes.Buffer)
	encoder := gob.NewEncoder(buffer)
	err := encoder.Encode(data)
	if err != nil {
		panic(err)
	}
	err = ioutil.WriteFile(filename, buffer.Bytes(), 0600)
	if err != nil {
		panic(err)
	}
}

func binWrite() {
	// t := time.Now().Nanosecond()
	fp, _ := os.Create("./binary.db")
	defer fp.Close()
	// rand.Seed(int64(t))
	buf := new(bytes.Buffer)
	binary.Write(buf, binary.LittleEndian, []byte("616221de418816e5"))
	fp.Write(buf.Bytes())
}
